###############################################################################
 # Copyright (C) 2010 Chris Wroe
 #
 # Modifications to the initial code base are copyright of their respective
 # authors, or their employers as appropriate.
 #
 # This program is free software; you can redistribute it and/or modify it under
 # the terms of the GNU Lesser General Public License as published by the Free
 # Software Foundation; either version 2.1 of the License, or (at your option)
 # any later version.
 #
 # This program is distributed in the hope that it will be useful, but WITHOUT
 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 # details.
 #
 # You should have received a copy of the GNU Lesser General Public License
 # along with this program; if not, write to the Free Software Foundation, Inc.,
 # 59 Temple Place, Suite 330, Boston, MA 02111-1307
 ##############################################################################

require "rubygems"
require "neo4j"
require 'neo4j/extensions/reindexer'

class ComponentModule; end

class Release
  include Neo4j::NodeMixin
  property :name
  index :name
  has_n(:modules).from(ComponentModule,:release)
end

class ComponentModule
  include Neo4j::NodeMixin
  property :name
  index :name
  has_one(:release).to(Release)
end

class ComponentFile
  include Neo4j::NodeMixin
  property :name
  index :name
  has_one(:release).to(Release)
  has_n(:modules).to(Module)
end




class Concept
	include Neo4j::NodeMixin
	property :name
  property :snomed_code ,:primitive_flag,:ctv3_code,:snomed_legacy_code,:concept_status, :version
  has_n(:isa_relations).to(Concept)
	has_n(:intrinsic_relations).to(Concept)
  has_n(:extrinsic_relations).to(Concept)
  has_n(:historical_relations).to(Concept)
  has_n(:qualifier_relations).to(Concept)
	index :name, :tokenized => true
  index :snomed_code
  index :version

	def to_s
		"Concept #{self.snomed_code} #{self.name}"
	end

end




class Description
  include Neo4j::NodeMixin
  property :term
  property :description_id, :description_type, :description_status, :language_code, :initial_capital_status, :version
  has_one(:concept).to(Concept)
  index :term, :tokenized => true
  index :description_id
  index :version

  def to_s
    "Description #{self.description_id} #{self.term}"
  end
end

class Preferred_Description < Description
  def to_s
    "Preferred Description #{self.description_id} #{self.term}"
  end
end

class Mapping_Target
  include Neo4j::NodeMixin
  property :scheme_id,:target_advice,:target_rule,:target_code,:target_id
  index :target_code, :tokenized => true
  index :target_id
end

class Mapping
  include Neo4j::NodeMixin
  has_n(:source_mapping).to(Concept)
  has_n(:target_mapping).to(Mapping_Target)
  property :map_option,:map_rule,:map_advice,:map_priority

  def to_s
    "Mapping #{self.source_mapping.name} to #{self.target_mapping.name}"
  end
end


class ICD_Code
  include Neo4j::NodeMixin
  property :name,:code
  index :name, :tokenized => true
  index :code

  def to_s
    "ICD #{self.code} #{self.name}"
  end
end



